package com.byzk.p2p.admin.user.controller;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.byzk.p2p.admin.base.controller.AdminBaseController;
import com.byzk.p2p.admin.base.util.PageInfo;
import com.byzk.p2p.admin.user.service.UserAccountService;
import com.byzk.p2p.admin.user.vo.UserAccountVo;

/**
 * 用户资金操作层
 * @author suker.zhou
 *
 */
@RequestMapping("/admin/userAccount")
@Controller
public class UserAccountController extends AdminBaseController {

	@Autowired
	private UserAccountService userAccountService;
	
	/**
	 * 分页显示用户资金总览信息
	 * @param model 视图对象
	 * @param index 当前页数
	 * @param limit 每页显示条数
	 * @param username 用户名
	 * @param match 匹配符 EQ("="), GT(">"), LT("<"), GE(">="), LE("<="), NE("<>");
	 * @param amount 总金额
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value="/list")
	public String listUserAccount(Model model,
							@RequestParam(value="index",required=false,defaultValue="1") int index,
							@RequestParam(value="limit",required=false,defaultValue="10") int limit,
							@RequestParam(value="username",required=false) String username,
							@RequestParam(value="match",required=false) String match,
							@RequestParam(value="amount",required=false) Double amount) throws Exception{
		UserAccountVo userAccountVo = new UserAccountVo();
		userAccountVo.setIndex(index);
		userAccountVo.setLimit(limit);
		if (StringUtils.isNotBlank(username)) {
			username=java.net.URLDecoder.decode(username , "UTF-8");
			userAccountVo.setMatchUser(username);
			model.addAttribute("username", username);
		}
		if (StringUtils.isNotBlank(match)) {
//			EQ("="), GT(">"), LT("<"), GE(">="), LE("<="), NE("<>");
			if (match.equals("EQ")) {
				userAccountVo.setMatchEQ(match);
			}else if (match.equals("GT")) {
				userAccountVo.setMatchGT(match);
			}else if (match.equals("LT")) {
				userAccountVo.setMatchLT(match);
			}else if (match.equals("GE")) {
				userAccountVo.setMatchGE(match);
			}else if (match.equals("LE")) {
				userAccountVo.setMatchLE(match);
			}else if (match.equals("NE")) {
				userAccountVo.setMatchNE(match);
			}
			model.addAttribute("match", match);
		}
		if (amount != null) {
			userAccountVo.setTotalAmount(amount);
			model.addAttribute("amount", amount);
		}
		PageInfo<UserAccountVo> pageInfo=userAccountService.listAll(userAccountVo);
		model.addAttribute("pageInfo", pageInfo);
		return ftl(Thread.currentThread().getStackTrace());
	}
	
	
}
